<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建聘费合同</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>持证人</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="personid" class="layui-input personid" onclick="openPage('../public/choose_person.php?dom=personid&page=cert_employ','80%','80%')">
                            <div class="choose_div" id="personid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_person.php?dom=personid&page=cert_employ','80%','80%')">
                                <i class="layui-icon layui-icon-search"></i>
                            </span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>人员性质</label>
                        <div class="layui-input-block">
                            <div id="person_nature"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">签约日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="sign_dt" id="sign_dt" placeholder="请选择" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>聘用资格</label>
                        <div class="layui-input-block">
                            <div id="qualification"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">聘用渠道</label>
                        <div class="layui-input-block">
                            <div id="channel"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">聘用说明</label>
                        <div class="layui-input-block">
                            <textarea id="employ_explain" name="employ_explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">证件用途</label>
                        <div class="layui-input-block">
                            <div id="purpose"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">是否可驻场</label>
                        <div class="layui-input-block">
                            <select class="layui-select" name="iszhu" id="iszhu"></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>聘费支付方式</label>
                        <div class="layui-input-block">
                            <select name="pay_type" class="layui-select pay_type" id="pay_type" lay-filter="pay_type" key="1"></select>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label" id="money_label"><text>*</text>聘费(元)</label>
                        <div class="layui-input-block">
                            <input type="text" placeholder="请填写" name="money" id="money" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">聘费说明</label>
                        <div class="layui-input-block">
                            <textarea id="pin_explain" name="pin_explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>聘期开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="start_dt" id="start_dt" placeholder="请输入" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>聘期结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="end_dt" id="end_dt" placeholder="请输入" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目补贴(元/月)</label>
                        <div class="layui-input-block">
                            <input type="text" name="subsidy" id="subsidy" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">出场费(元/次)</label>
                        <div class="layui-input-block">
                            <input type="text" name="out_fee" id="out_fee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">银行账户名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="account" id="account" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">银行账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="account_num" id="account_num" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="open_bank" id="open_bank" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var personid = getQueryVariable('personid');
    // var personname = getQueryVariable('personname');
    // if(personid != undefined && personid != false){
    //     set_choose_btn('personid',personid,decodeURI(personname),'请选择人员姓名');
    // }

    $("#commentForm").validate({
        rules: {
            money: {required: true},
            start_dt: {required: true},
            end_dt: {required: true},
        },
        messages:{
            money: {required: "请输入聘费"},
            start_dt: {required: "请选择聘期开始时间"},
            end_dt: {required: "请选择聘期结束时间"},
        }
    });

    var person_nature;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_cert_employ_add,data:{personid:personid}}).done(function(res){
            if (res.code === 2000) {

                person_nature = res.data.person_nature;

                if(res.data.person){
                    set_choose_btn('personid',res.data.person.id,res.data.person.name,'请选择人员姓名');
                    xmselect_dan('person_nature', res.data.person_nature, res.data.person.nature, function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#person_nature").find('xm-select').removeClass('error');
                        }else{
                            $("#person_nature").find('xm-select').addClass('error');
                        }
                    });
                }else{
                    xmselect_dan('person_nature', res.data.person_nature, '', function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#person_nature").find('xm-select').removeClass('error');
                        }else{
                            $("#person_nature").find('xm-select').addClass('error');
                        }
                    });
                }


                var iszhu = res.data.iszhu;
                var iszhu_str = '<option value=""></option>';
                for (var i in iszhu){
                    iszhu_str += '<option value="'+i+'">'+iszhu[i]+'</option>';
                }
                $('#iszhu').html(iszhu_str);

                var pay_type = res.data.pay_type;
                var pay_type_str = '<option value=""></option>';
                for (var i in pay_type){
                    pay_type_str += '<option value="'+i+'">'+pay_type[i]+'</option>';
                }
                $('#pay_type').html(pay_type_str);


                xmselect_dan('channel', res.data.channel, '');
                xmselect_duo('qualification', res.data.qualification, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#qualification").find('xm-select').removeClass('error');
                    }else{
                        $("#qualification").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('purpose', res.data.purpose, '');


                public_upload_file_load('upload_file');
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            data.field.personid = get_choose_val('personid');
            if(!data.field.personid){
                formValid('personid', '请选择持证人'); validRes = false;
            }else{
                formValid('personid', '');
            }
            if(!data.field.person_nature){
                $("#person_nature").find('xm-select').addClass('error'); validRes = false;
            }else{
                $("#person_nature").find('xm-select').removeClass('error');
            }
            if(!data.field.qualification){
                $("#qualification").find('xm-select').addClass('error'); validRes = false;
            }else{
                $("#qualification").find('xm-select').removeClass('error');
            }
            if(!data.field.pay_type){
                formValid('pay_type', '请选择支付方式'); validRes = false;
            }else{
                formValid('pay_type', '');
            }
            if(!validRes){return false;}

            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);
            facade.ajax({url: ask_cert_employ_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });
    });
</script>
</body>
</html>
